package com.simple.auth.handler;

import com.simple.framework.core.domain.R;
import com.simple.framework.utils.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 验证失败处理器
 * @Author xiaoke
 * @Date 2024/8/10 18:00
 * @Version 1.0
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        R<Void> responseResult = R.fail(401,"token无效");
        WebUtils.writeJson(response,responseResult);
    }
}
